import React, { useEffect, useState } from 'react'

function SubRender (props) {
    const { total } = props
    const [sub, setSub] = useState(total)
    useEffect(() => {
        setSub(total - 10)
    }, [total])

    return (
        <div>
            <div>sub Hook total: {total}</div>
            <div>sub Hook sub: {sub}</div>

            <button onClick={() => setSub(total - 5)}>获取sub的值</button>
        </div>
    )
}
function SubHook(props) {
    const { total } = props
    if(total < 100){
        return <div>小于100</div>
    }
    else{
        return <SubRender total={total}/>
    }
}

export default SubHook
